//
//  Demo1TabView.swift
//  CHSimpleUI
//
//  Created by cyptt on 2023/5/22.
//

import UIKit
import CHSimpleUI
class Demo1TabView: UIView,UITableViewDelegate  {

    
    var tabdataSource:Demo1DataSource?
    
    let cellID:String = "CELLID"
    
    var viewModel:Demo1ViewModel?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(self.tableView)
        
        self.tableView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        
       
        tabdataSource = Demo1DataSource.init(identifier: self.cellID) { cell, model, indexPath, tableView in
          
        }
        self.viewModel = Demo1ViewModel.init { vModelResult in
            self.tabdataSource?.datas = vModelResult as! [Any]
            self.tableView.reloadData()
        }failBlock: { vModelFailMsg in
            
        }
        
        self.viewModel?.refreshData()
        
        self.tableView.dataSource  = self.tabdataSource
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var tableView = {()-> UITableView in
        let tabV = UITableView.init();
        tabV.backgroundColor = UIColor.clear
        tabV.separatorColor = UIColor.clear
    
        tabV.delegate = self
        return tabV;
    }()
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
        return 200
    }
}


